package S16.first;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Comparator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class F02 {

	public static void main(String[] args) throws IOException {
		Path path = Paths.get("./src/S16/first/en.txt");
//		Stream<Entry<Character, Long>> sorted = 
		Files.lines(path)
			.flatMap(s->s.chars().mapToObj(i->(char)i))
			.filter(Character::isLetter)
			.map(Character::toLowerCase)
			.collect(Collectors.groupingBy(c->c, Collectors.counting()))
			.entrySet().stream()
			.sorted(Map.Entry.<Character, Long>comparingByValue().reversed())
			.forEach(e->System.out.println(e.getKey()+"\t"+e.getValue()));

	}

}
